package com.sunkyc.framework.utils;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.RandomGenerator;
import cn.hutool.core.util.IdUtil;
import com.sunkyc.commons.entity.Captcha;

public class CaptchaUtils {

    /**
     * 生成验证码
     * @return 验证码实体
     */
    public static Captcha createCaptcha(){
        RandomGenerator randomGenerator = new RandomGenerator("0123456789", 4);
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 70);
        lineCaptcha.setGenerator(randomGenerator);
        return new Captcha().setCode(lineCaptcha.getCode())
                .setImageData(lineCaptcha.getImageBase64Data())
                .setUuid(IdUtil.fastSimpleUUID().toLowerCase());
    }


}
